/**
 * Created by HUANGFR2 on 8/21/2016.
 */
angular.module('order_complaint', []).controller('order_complaintController', function ($scope, $rootScope, $http, $uibModal, ComplaintService) {
    //console.log('order_complaint init');
    $rootScope.active = 'cl';
    
    $http.get('/complaint')
        .then(function (res) {
            var data = res.data;
            if (data.msg == 'SUCCESS') {
                //order_complaintResolver(data.complaints);
                $scope.complaints = data.complaints;
            } else {
                alert('get order complaint error : ' + data.error);
            }
        }, function (res) {
            alert('get order complaint error : ' + res.error);
        });

    $scope.updateStatus = function(complaint, status){
        ComplaintService.updateComplaintStatus(complaint, status);
    };

    $scope.openWarning = function (complaint) {
        var modalInstance = $uibModal.open({
            animation: true,
            ariaLabelledBy: 'modal-title',
            ariaDescribedBy: 'modal-body',
            templateUrl: 'merchantWarning_modal.html',
            controller: 'complaintWarningModalController',
            size: 'sm',
            resolve: {
                parentScope : function () {
                    return $scope
                },
                complaint : function () {
                    return complaint
                }
            }
        });
    }
});

angular.module('order_complaint').controller('complaintWarningModalController', function ($scope, $http, $uibModalInstance, parentScope, complaint) {
    $scope.merchant = complaint.detail.merchant;
    $scope.confirm = function () {
        parentScope.updateStatus(complaint, 3);
        $scope.cancel();
    };

    $scope.cancel = function () {
        $uibModalInstance.dismiss('cancel');
    };
});

